
AspireBid.Config = {}
AspireBid.Config.Frame = nil;


-- Toggle the config frame on/off
AspireBid.Config.Toggle = function( )
	if ( AspireBid.Config.Frame ~= nil and AspireBid.Config.Frame:IsVisible() ) then
		AspireBid.Config.Hide();
	else
		AspireBid.Config.Show();
	end	
end

AspireBid.Config.Show = function( )
	-- Initialize Frame
	AspireBid.Config.Init();
	-- Load Settings
	AspireBid.Config.LoadSettings();	
	-- Show Frame
	AspireBid.Config.Frame:Show();
end

AspireBid.Config.Hide = function( )
	AspireBid.Config.SaveSettings();
	AspireBid.Config.Frame:Hide();
end

AspireBid.Config.LoadSettings = function( )
	AspireBid.Config.ILevel:SetText( AspireBid.LocalGetSetting( "ItemLevel" ) );
	AspireBid.Config.Plate:SetChecked( AspireBid.LocalGetSetting( "Plate" ) );
	AspireBid.Config.Mail:SetChecked( AspireBid.LocalGetSetting( "Mail" ) );
	AspireBid.Config.Leather:SetChecked( AspireBid.LocalGetSetting( "Leather" ) );
	AspireBid.Config.Cloth:SetChecked( AspireBid.LocalGetSetting( "Cloth" ) );
	AspireBid.Config.Minimap:SetChecked( AspireBid.BaseGetSetting( "MinimapShown" ) );
end

AspireBid.Config.SaveSettings = function( )
	AspireBid.LocalSetSetting( "ItemLevel", AspireBid.Config.ILevel:GetText() );
	AspireBid.LocalSetSetting( "Plate", AspireBid.Config.Plate:GetChecked() );
	AspireBid.LocalSetSetting( "Mail", AspireBid.Config.Mail:GetChecked() );
	AspireBid.LocalSetSetting( "Leather", AspireBid.Config.Leather:GetChecked() );
	AspireBid.LocalSetSetting( "Cloth", AspireBid.Config.Cloth:GetChecked() );
	
	if AspireBid.Config.Minimap:GetChecked() then	
		AspireBid.BaseSetSetting( "MinimapShown", true );
	else
		AspireBid.BaseSetSetting( "MinimapShown", false );
	end
		
	AspireBid.Minimap:AddonLoaded();	
end

-- Initialize config frame
AspireBid.Config.Init = function( )
	if ( AspireBid.Config.Frame~=nil ) then
		return;
	end
	
	AspireBid.Config.Frame = CreateFrame( "Frame", "AspireBidConfigFrame1", UIParent, "AspireBidConfigFrame" ); 
	
	-- Proficiency label
	local label = CreateFrame( "Frame", "ABConfigLabel1", AspireBid.Config.Frame, "AspireBidLabelTemplate" );
	label.Label:SetText( "Show window on items with the following proficiency: " );
	label:SetPoint( "TOPLEFT", 20, -20 );
	label:Show();
	
	-- Create Armor Type checkboxes
	local plate = CreateFrame( "CheckButton", "ABConfigPlate", AspireBid.Config.Frame, "AspireBidCheckTemplate" );
	plate.Label:SetText( "Plate" );
	plate:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 10, 0);
	plate:Show()
	AspireBid.Config.Plate = plate;
	
	-- Create Mail type checkbox
	local mail = CreateFrame( "CheckButton", "ABConfigMail", AspireBid.Config.Frame, "AspireBidCheckTemplate" );
	mail.Label:SetText( "Mail" );
	mail:SetPoint("TOPLEFT", plate, "BOTTOMLEFT", 0, 0);
	mail:Show()
	AspireBid.Config.Mail = mail;
	
	-- Create Leather type checkbox
	local leather = CreateFrame( "CheckButton", "ABConfigLeather", AspireBid.Config.Frame, "AspireBidCheckTemplate" );
	leather.Label:SetText( "Leather" );
	leather:SetPoint("TOPLEFT", mail, "BOTTOMLEFT", 0, 0);
	leather:Show()
	AspireBid.Config.Leather = leather;
	
	-- Create Leather type checkbox
	local cloth = CreateFrame( "CheckButton", "ABConfigCloth", AspireBid.Config.Frame, "AspireBidCheckTemplate" );
	cloth.Label:SetText( "Cloth" );
	cloth:SetPoint("TOPLEFT", leather, "BOTTOMLEFT", 0, 0);
	cloth:Show()
	AspireBid.Config.Cloth = cloth;
	
	
	
	-- iLevel label
	local label2 = CreateFrame( "Frame", "ABConfigLabel2", AspireBid.Config.Frame, "AspireBidLabelTemplate" );
	label2.Label:SetText( "Show window on items with iLevel greater or equal to: " );
	label2:SetPoint( "TOPLEFT", label, "BOTTOMLEFT", 0, -120 );
	label2:Show();
	
	-- ilevel input
	local ilevel = CreateFrame( "EditBox", "ABConfigIlevel", AspireBid.Config.Frame, "AspireBidInputTemplate" );
	ilevel:SetPoint( "TOPLEFT", label2, "BOTTOMLEFT", 20, 0 );
	ilevel:Show();
	AspireBid.Config.ILevel = ilevel;
	
	
	-- Minimap
	local minimap = CreateFrame( "CheckButton", "ABConfigMinimap", AspireBid.Config.Frame, "AspireBidCheckTemplate" );
	minimap.Label:SetText( "Show Minimap Button" );
	minimap:SetPoint("TOPLEFT", cloth, "BOTTOMLEFT", 0, -80);
	minimap:Show()
	minimap:SetScript("OnClick", function(self, button, down)
  		if self:GetChecked() then
  			AspireBid.Minimap:Show()
  		else
  			AspireBid.Minimap:Hide()
  		end
	end)
	
	AspireBid.Config.Minimap = minimap;
	
	
	-- Close Button
	local button = CreateFrame( "Button", "ABCloseButton", AspireBid.Config.Frame, "UIPanelButtonTemplate" );
	button:SetHeight( "24" );
	button:SetWidth( "60" );
	button:SetText( "Close" );
	button:SetPoint( "BOTTOM", AspireBid.Config.Frame, "BOTTOM", 0, 20 );
	button:SetScript( "OnClick", function(self, button) 
		AspireBid.Config.Hide();
	end);
	button:Show();
	
end